package com.dang.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**这是一个初始化用的listener
 * 比如后台添加了数据前台只用在Application中同步数据就行
 * 需要配置lisnnter
 * 实现了ServletContextListener接口的类才可以被监听
 * 因为传到Application中使用ApplicationContextAware
 * 可以获取到当前Application
 * */
public class InitListener implements ServletContextListener,ApplicationContextAware{
	
	@SuppressWarnings("unused")
	private static ApplicationContext applicationContext;
	
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		//这是一个销毁时候调用的方法
	}

	@Override
	public void contextInitialized(ServletContextEvent servletContextEvent) {
		//初始化方法
		@SuppressWarnings("unused")
		ServletContext application = servletContextEvent.getServletContext();  //获取网站的Applocation
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		InitListener.applicationContext=applicationContext;
		
	}

}
